package cn.tangcent.rules;

import cn.tangcent.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by TangMing on 2017/4/8.
 * 规则:每列中每个数字必出现一次
 * 如果每列中某个数字只能出现在某格，则此格中数字可确定
 */
public class ColumnRule extends PartitionRule {
    @Override
    public int selected(SudokuData sudokuData, int colum) {
        return sudokuData.sy(colum);
    }

    @Override
    public void check(SudokuData sudokuData, int column, int selected) {
        //收集空位
        Coordinate[] blanks = sudokuData.todos(SudokuUtils.entireColumn(column));
        Integer[] optionals = sudokuData.optionals(blanks);
        for (int i = 0; i < optionals.length; i++) {
            int finalI = i;
            SudokuUtils.forBit(optionals[i], o -> {
                setFlag(o, blanks[finalI]);
            });
        }
    }
}
